<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>粘滞定位</title>
    <style>

        body{
            height: 4000px;
        }

        .box1{
            width: 1200px;
            height: 40px;
            background-color: tomato;
            margin: 100px auto;

            /*
                将元素的position设置sticky则开启了元素的粘滞定位，
                    粘滞定位的特点和相对定位类似
                定位参照物：
                    粘滞定位相对于离它最近的拥有滚动条祖先元素来定位的
            */
            position: sticky;
            top: 0;
        }
    </style>
</head>
<body>

    <div class="box1"></div>

    <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, dolorum eligendi incidunt omnis recusandae similique sint! Adipisci aspernatur dolores dolorum, facilis harum libero molestiae, nulla pariatur qui, recusandae veniam voluptatum.
    </p>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, dolorum eligendi incidunt omnis recusandae similique sint! Adipisci aspernatur dolores dolorum, facilis harum libero molestiae, nulla pariatur qui, recusandae veniam voluptatum.
    </p>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aspernatur, dolorum eligendi incidunt omnis recusandae similique sint! Adipisci aspernatur dolores dolorum, facilis harum libero molestiae, nulla pariatur qui, recusandae veniam voluptatum.
    </p>
</body>
</html>